// 获取应用实例
const app = getApp()

import Toast from '../../vant-weapp/dist/toast/toast';

Page({
  data: {
    imgUrls:[
      "http://img-arch.pconline.com.cn/images/upload/upc/tx/photoblog/1405/19/c2/34380494_1400468348929.jpg",
      "http://img-arch.pconline.com.cn/images/upload/upc/tx/photoblog/1405/19/c2/34380494_1400468348929.jpg",
      "http://img-arch.pconline.com.cn/images/upload/upc/tx/photoblog/1405/19/c2/34380494_1400468348929.jpg",
    ],
    listData: [],
    current: 'links',
    // 实现轮播宫格效果
    // 轮播图部分
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 500,
    indicatorColor: '#ff7440', 
    indicatorActiveColor: '#000000',
    //九宫格部分
    grids: [0, 1, 2, 3, 4, 5, 6, 7],
    // 服务列表
    service: [],
    // 通告栏消息
    notice:'',
    // 今日课表列表
    todayClass:[],
    // 用户是否登录
    isLogin:false
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },


  onLoad() {
    // 请求 
    this.getService()
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },

  onShow: function(){
    var that = this
    that.setData({
      isLogin: app.globalData.isLogin
    })
  },

  //grid跳转
  toGridDetail: function (event) {
    // let index = event.currentTarget.dataset.idex;
    wx.navigateTo({
      url: '../category/category',
    })
  },

  getService: function (){
    var that = this
    wx.request({
      url: 'https://example.com/index',
      dataType: 'json',
      success(res) {
        console.log(res)
        console.log(res.data.todayClass)
        console.log("--------------------")
        that.setData({
          service: res.data.service,
          notice: res.data.notice,
          todayClass: res.data.todayClass
        })
        console.log(that.data.todayClass)
        
      }
    })
  },

  goToClass(){
    // 用户已登录
    if(this.data.isLogin != false){
      wx.navigateTo({
        url: '/pages/class/class',
      })
    }else{
      Toast({message:'未登录',selector:'#noLogin'});
    }
  },

  goToExam(){
    // 用户已登录
    if(this.data.isLogin != false){
      wx.navigateTo({
        url: '/pages/exam/exam',
      })
    }else{
      Toast({message:'未登录',selector:'#noLogin'});
    }
  },

  goToResults(){
    // 用户已登录
    if(this.data.isLogin != false){
      wx.navigateTo({
        url: '/pages/results/results',
      })
    }else{
      Toast({message:'未登录',selector:'#noLogin'});
    }
  },

  goToSchoolNav(){
    // 用户已登录
    if(this.data.isLogin != false){
      wx.navigateTo({
        url: '/pages/schoolNav/schoolNav',
      })
    }else{
      Toast({message:'未登录',selector:'#noLogin'});
    }
  }

})
